<template>
	<view class="home">
		<navbar></navbar>
		<tab :list="labelList" @tab="tabChange" :labelIndex="labelIndex"></tab>
		<view class="home-list">
			<list :tab="labelList" :activeIndex="activeIndex" @change="change"></list>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				labelList: [],
				activeIndex: 0,
				labelIndex: 0
			};
		},
		onLoad() {
			uni.$on('labelChange', () => {
				this.labelList = [],
				this.activeIndex = 0,
				this.labelIndex = 0
				this.getLabel()
			})
			this.getLabel()
		},
		// onShow() {
		// 	this.getLabel()
		// },
		methods: {
			change(current) {
				this.labelIndex = current
				this.activeIndex = current
				// console.log(current);
			},
			getLabel() {
				this.$api.get_label().then(res => {
					// console.log(res);
					this.labelList = res.data
					this.labelList.unshift({
						name: '全部'
					})
				})
			},
			tabChange({
				item,
				index
			}) {
				this.activeIndex = index
				// console.log(item, index);
			}
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
		display: flex;
	}

	.home {
		display: flex;
		flex-direction: column;
		flex: 1;
		overflow: hidden;

		.home-list {
			flex: 1;
			box-sizing: border-box;
		}
	}
</style>
